#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;


int main(){
	int n;
	cin>>n;
	int a[n+1],dp[n+1];
	a[0] = -1;
	dp[0] = -1;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int R=0;
	for(int i=1;i<=n;i++){
		if(a[i] > dp[R])
			dp[++R] = a[i];
		else
			dp[lower_bound(dp,dp+R+1,a[i])-dp] = a[i];
	}
//	for(int i=0;i<=n;i++)
//		cout<<dp[i]<<" ";
//	cout<<endl;
	cout<<R;
	return 0;
}
